<?php

namespace App\Http\Controllers\OpenShop\SiteLocation;

use App\Http\Controllers\BaseController;
use App\Service\SiteLocation\DevelopmentMangerService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class DevelopmentManagerController extends BaseController
{
    /**
     * 数据总览
     * @param Request $request
     * @return JsonResponse
     */
    public function overview(Request $request): JsonResponse
    {
        return $this->success(DevelopmentMangerService::overview());
    }


    /**
     * 列表
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function list(Request $request): JsonResponse
    {
        $rmsUserId = getRmsUserId();
        $pageNum   = (int)$request->get('pageNum', 1);
        $pageSize  = (int)$request->get('pageSize', 20);

        // 筛选参数
        $provinceCode      = (int)$request->get('provinceCode', 0);
        $cityCode          = (int)$request->get('cityCode', 0);
        $districtCode      = (int)$request->get('districtCode', 0);
        $isResigned        = (string)$request->get('isResigned', '');
        $phone             = (string)$request->get('phone', '');
        $userId            = (string)$request->get('userId', '');
        $sort              = (string)$request->get('sort', '');
        $followUpStartTime = (string)$request->get('followUpStartTime', '');
        $followUpEndTime   = (string)$request->get('followUpEndTime', '');
        $onTheJobStartTime = (string)$request->get('onTheJobStartTime', '');
        $onTheJobEndTime   = (string)$request->get('onTheJobEndTime', '');
        $sortField         = (string)$request->get('sortField', '');
        $sortOrder         = (string)$request->get('sortOrder', '');

        return $this->success(
            DevelopmentMangerService::list($pageNum, $pageSize, $provinceCode, $cityCode, $districtCode, $isResigned, $phone, $userId, $sort, $followUpStartTime, $followUpEndTime, $onTheJobStartTime, $onTheJobEndTime, $rmsUserId, $sortField, $sortOrder)
        );
    }


    /**
     * 夸父开发经理基本详情
     * @param Request $request
     * @param $userId
     * @return JsonResponse
     */
    public function baseDetail(Request $request, $userId): JsonResponse
    {
        return $this->success(DevelopmentMangerService::baseDetail($userId));
    }


    /**
     * 开发经理详情列表
     * @param Request $request
     * @param $userId //开发经理ID
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws ValidationException
     */
    public function taskDetail(Request $request, $userId): JsonResponse
    {
        $this->validate($request, [
            'type' => 'required|int',
        ]);

        $rmsUserId = getRmsUserId(); // 当前用户
        $type      = (int)$request->get('type');
        $grade     = (string)$request->get('grade', '');
        $cityCode  = (int)$request->get('cityCode', 0);
        $pageNum   = (int)$request->get('pageNum', 1);
        $pageSize  = (int)$request->get('pageSize', 20);

        return $this->success(DevelopmentMangerService::taskDetail($rmsUserId, $type, $pageNum, $pageSize, $grade, $cityCode, $userId));
    }


    /**
     * 开发经理任务涉及区域
     * @param Request $request
     * @param $userId //开发经理ID
     * @return JsonResponse
     */
    public function involve(Request $request, $userId): JsonResponse
    {
        return $this->success(DevelopmentMangerService::involve($userId));
    }


}
